﻿@inherits LayoutComponentBase
@inject I18n I18n
@inject NavigationManager NavigationManager
@inject DocService DocService
@inject MasaBlazor MasaBlazor
@inject LocalStorage LocalStorage
@inject IJSRuntime JSRuntime
@implements IDisposable

<HeadContent>
    <PageTitle>@_projectInfo?.Name</PageTitle>
    <link rel="icon" href="@_projectInfo?.IconUrl" type="image/x-icon">
</HeadContent>

<MApp Class="body-large">
    <CascadingValue Value="@I18n.Culture.ToString()" Name="Culture">
        <CascadingValue Value="@_project" Name="project">
            <MErrorHandler DisablePopupIfErrorContentRender>
                <ChildContent>
                    <CascadingValue Value="@_env" Name="Env">
                        <AppBar OnCultureChanged="@OnCultureChanged"
                                OnAppBarNavIconClick="@HandleOnAppBarNavIconClick"
                                OnDotClick="@HandleOnDotClick"
                                OnSettingsClick="@HandleSettingsClick"
                                HideAppBarNavIcon="@_hideAppBarNavIcon"
                                ProjectInfo="@_projectInfo"/>
                    </CascadingValue>

                    <CascadingValue Value="this" IsFixed>
                        <CascadingValue Value="@(Config?.NavComponentsGroupByType ?? true)"
                                        Name="ComponentsGroupByType">
                            @Body
                        </CascadingValue>
                    </CascadingValue>

                    <Settings @bind-Value="_showSettings" Config="@Config" ConfigChanged="@OnConfigChanged"/>

                    <MobileMenuList @bind-Value="_showMobileMenuList"/>
                </ChildContent>
                <ErrorContent>
                    <MContainer Class="fill-height justify-center">
                        <div style="white-space: pre-wrap; max-width: 100vw;">
                            <h1 class="error--text text-center mb-6">Something went wrong</h1>
                            <p class="error--text" style="font-size: 1rem;">@context.Message</p>
                            <p class="info--text">This could be a browser cache issue. Refresh and try again, or
                                manually hard reload (<kbd>Ctrl+F5</kbd> for Windows, <kbd>Command+Shift+R</kbd> for
                                Mac).</p>
                            <MButton Block
                                     Class="text-capitalize"
                                     Large
                                     Color="primary"
                                     OnClick="RefreshPage">
                                @I18n.T("pwa.refresh")
                            </MButton>
                        </div>
                    </MContainer>
                </ErrorContent>
            </MErrorHandler>
        </CascadingValue>

        <PwaSnackbar OnRefresh="@RefreshToSkipWaiting"/>
    </CascadingValue>
</MApp>
